﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace AStar.Class
{
    [Serializable]
    public class City : IComparable
    {
        private float x;
        private float y;
        private String name;
        private float lenght;
        private City before;
        private float maxLength;

        public float MaxLength
        {
            get { return maxLength; }
            set { maxLength = value; }
        }

        internal City Before
        {
            get { return before; }
            set { before = value; }
        }

        public float Lenght
        {
            get { return lenght; }
            set
            {
                lenght = value;
            }
        }

        public City(String name, float x, float y)
        {
            this.name = name;
            this.x = x;
            this.y = y;
            lenght = 0;
            maxLength = 0;
            before = null;
        }

        public float X
        {
            get { return x; }
        }

        public float Y
        {
            get { return y; }
        }

        public String Name
        {
            get { return name; }
        }

        public PointF Location
        {
            get { return new PointF(x, y); }
        }

        public int CompareTo(object obj)
        {
            return maxLength.CompareTo(((City)obj).MaxLength);
        }

        public void Estimate(City destination)
        {
            float diffx = x - destination.X;
            float diffy = y - destination.Y;
            double getLength = diffx * diffx + diffy * diffy;
            maxLength = lenght + (float)Math.Sqrt(getLength);
        }
    }
}
